<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script>
			function formData(name, arr) {
				this.name = name;
				this.job = arr;
				this.testFun = function() {};
				if (typeof(this.clearAll) != 'function') { // 避免重复执行占内存
					console.log('初始化开始')
					formData.prototype.clearAll = function() {
						console.log(this, 'clearAll')
						return this.name + this.job
					}
					console.log('初始化结束')
				}
			}
			var xiaoli = new formData('xiaoli', ['农民', '工人']);
			var xiaochen = new formData('xiaochen', ['教师', '程序员'])
			xiaoli.clearAll()
			xiaochen.clearAll()
			// console.log(typeof(NaN)) // number

			function Fac() {
				let ab = {}
				ab.a = 1
				ab.b = 2
				ab.fn = () => {
					let sum = ab.a + ab.b
					console.log(sum, 'sumFac')
					return sum
				}
				return ab
			}
			Fac().fn()
			Fac().fn()

			function Constructor(...args) {
				const [a, b] = args
				this.a = a
				this.b = b
				this.fn = function() {
					let sum = this.a + this.b
					console.log(sum, 'sumCons')
					return sum
				}
			}
			let sumCons = new Constructor(1, 2)
			let sumCons2 = new Constructor(1, 2)
			console.log(sumCons.fn == sumCons2.fn, "space") // false

			function Prototype(...args) {}
			Prototype.prototype = {
				constructor: Prototype,
				a: 1,
				b: 2,
				c: [1],
				fn: function() {
					const sum = this.a + this.b
					console.log(sum, "sumPrototype")
					return sum
				}
			}
			Prototype.prototype.fn()
			const newProto = new Prototype()
			newProto.c.push(3)
			const newProto2 = new Prototype()
			newProto2.c.push(4)
			console.log(newProto.fn == newProto2.fn, "newProto") // true
			console.log(newProto.c, newProto2.c, "newProto") // 3
			// alert(newProto.constructor)
			

			function Parent(name, age) {
				this.name = name
				this.age = age
				this.fn = function() {
					return this.name + ' ' + this.age
				}
			}
			const nP = new Parent("name", "age")
			const obj = new Object()
			Parent.call(obj, "ab", 18)
			console.log(obj.fn(), 'obj')

			const Ob = {};
			(function(close) {
				console.log(close, "close1")
			}(nP));
			(function(close) {
				console.log(close, "close2")
			})(1)
		</script>
	</body>
</html>